#!/usr/bin/env python

from fulguro import *
# from flgrarith import *
# from flgrmorpho import *

# ##############################################################
# # BENCH PROCEDURE
# ##############################################################
# def benchmark(nbiter,function,*args):
#     t=time.time()
#     for i in range(nbiter):
#         function(*args)
#     t2=time.time()

#     print function.func_name + " = ",((t2-t)*1000)/nbiter,' ms'


# ##############################################################
# # PROCEDURE
# ##############################################################
# def lineErode(lineout,linetmp0,linetmp1,linein):
#     flgr1d_shift_right(linetmp0,linein, 1, 255)
#     flgr1d_shift_left(linetmp1,linein, 1, 255)
#     flgr1d_arith_inf(linetmp0,linetmp1,linetmp0)
#     flgr1d_arith_inf(lineout,linein,linetmp0)
    
    

# def squareErode(imgout,imgin):
#     tmpL0 = FLGR_Data1D(imgin[0])
#     tmpL1 = FLGR_Data1D(imgin[0])
#     tmp0 = FLGR_Data1D(imgin[0])
#     tmp1 = FLGR_Data1D(imgin[0])
#     tmp2 = FLGR_Data1D(imgin[0])
 
#     lineErode(tmp0,tmpL0,tmpL1,imgin[0])
#     lineErode(tmp1,tmpL0,tmpL1,imgin[1])

#     flgr1d_arith_inf(imgout[0],tmp0,tmp1)
   
#     for i in range(imgin.size_y-2):
#         j=i+1
#         k=j+1
#         lineErode(tmp2,tmpL0,tmpL1,imgin[k])
#         flgr1d_arith_inf(tmp0,tmp1,tmp0)
#         flgr1d_arith_inf(imgout[j],tmp0,tmp2)
        
#         tmpsav=tmp0
#         tmp0=tmp1
#         tmp1=tmp2
#         tmp2=tmpsav

#     flgr1d_arith_inf(imgout[imgin.size_y-1],tmp0,tmp1)

# ##############################################################
# # MAIN
# ##############################################################
# nhb = FLGR_Data2D(3,3,FLGR_UINT8,FLGR_RECT,FLGR_8_CONNEX)
# imin  = flgr2d_load_pgm('../../apps/images/gray/goldhill.pgm')
# imout = FLGR_Data2D(imin)

# benchmark(100,squareErode,imout,imin)
# flgr2d_arith_sub(imout,imin,imout)

# benchmark(5000,flgr2d_erode,imout,imin,nhb)

# flgr2d_save_pgm(imout,'shift_erode.pgm')



imin  = flgr2d_load_pgm('../../apps/images/gray/goldhill.pgm')
imout = FLGR_Data2D(imin)

vec = FLGR_Vector(1,FLGR_UINT8);
vec.populate(128)

flgr2d_replace(imout,imin,"<",128,imin,255)

flgr2d_draw_disc(imout,256,256,32,vec)

flgr_display(imin,imout,"in","out")
